﻿using FinancialManagement.Application.Command.ActualRefundCommand;
using FinancialManagement.Infrstructre.Interface;
using MediatR;

namespace FinancialManagement.Application.CommandHandler.ActualRefundCommandHandler
{
    public class DelActualRefundCommandHandler : IRequestHandler<DelActualRefundCommand, int>
    {

        ISalesShouldRefundRepository ssrRep;

        public DelActualRefundCommandHandler(ISalesShouldRefundRepository ssrRep)
        {
            this.ssrRep = ssrRep;
        }

        public async Task<int> Handle(DelActualRefundCommand request, CancellationToken cancellationToken)
        {
            var list = (await ssrRep.GetAllAsyns()).Where(c => request.SalesShouldRefundId.Contains(c.SalesShouldRefundId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelTime = DateTime.Now;
                await ssrRep.UpdateAsync(item);
            }
            return 1;
        }



    }
}
